package org.example.modules.Info.sevice.Impl;

import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.modules.Info.entry.SideJob;
import org.example.modules.Info.mapper.SideJobMapper;
import org.example.modules.Info.sevice.SideJobSevice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @Description SideJobSeviceImpl
 * @Author xiaotian
 * @Date 2025-03-22
 */
@Service
public class SideJobSeviceImpl extends ServiceImpl<SideJobMapper,SideJob> implements SideJobSevice  {
    @Autowired
    private SideJobMapper sideJobMapper;
    @Override
    public List<SideJob> getSideJobList(Object type) {
        if(type==null){
            return sideJobMapper.selectAllList();
        }else{
            Integer code = (Integer) type;
            LambdaQueryWrapper<SideJob> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(SideJob :: getType,code);
            return sideJobMapper.selectList(queryWrapper);
        }

    }

    @Override
    public List<SideJob> updateStatus(JSONObject data) {
        Integer id = data.getInteger("id");
        Integer targetStatus = data.getInteger("targetStatus");
        Integer currentStatus = data.getInteger("currentStatus");
        if(targetStatus==4){
            targetStatus=targetStatus*10+currentStatus;
        }else{
            targetStatus=currentStatus%10;
        }
        sideJobMapper.updateStatusByCode(id,targetStatus);
        return sideJobMapper.selectAllList();
    }
}
